<?php include PATH_TPL."/admin/tpl.header.phtml"?>
<div class="main-container inner">
    <div class="main-content">
        <div class="container-fluid">
            <div class="row bt">
                <div class="col-lg-12 bg">
                    <ol class="breadcrumb">
                        <li class="active">
                            <i class="fa  fa-fw fa-reorder"></i>修改账号
                        </li>
                    </ol>
                </div>
            </div>
            <div id="page-wrapper">
                <div class="container-fluid col-md-7 col-sx-12">
                    <form method="post" enctype="multipart/form-data" name="myform">
                        <div class="form-group">
                            <label for="name"><strong>账号名称</strong></label>  
                            <input type="text" placeholder="请输入邮箱" id="name" class="form-control" name="name" value="<?=$tARow['name']?>" readonly/>
                        </div>
                        <div class="form-group">
                            <label for="passwd" style="color:green"><strong>初始化密码</strong>(密码为6-16位数字、字母)</label>
                            <input type="password" placeholder="121212" id="passwd" class="form-control hidden" name="passwd" />
                        </div>
                        <div class="form-group" id="role">
                            <label for="role"><strong>账号角色</strong>&nbsp;&nbsp;&nbsp;&nbsp;</label></br>
                            <?if($tARow['role'] == 'hd_admin'){?>华道<?}?>
                            <?if($tARow['role'] == 'bx_admin'){?>保险公司<?}?>
                            <?if($tARow['role'] == 'qy_admin'){?>企业人资<?}?>
                            <input type="hidden" value="<?=$tARow['role']?>" name="role" />
                        </div>
                        <div class="form-group" id="companyDiv">
                            <label for="company"><strong>所属公司</strong></label></br>
                            <div id="company">
                                <input readonly type="text" value="<?=$tARow['company']?>">
                                <input type='hidden' value="<?=$tARow['company_code']?>" name="company">
                                <input type='hidden' value="<?=$tARow['b_company_code']?>" name="b_company">
                                <?if(count($tBCompany)){?>
                                <select name="bcompany">
                                <option value="">=请选择=</option>
                                <?foreach($tBCompany as $tRow){?>         
                                <option value="<?=$tRow['bc_id']?>"  <?if($tRow['bc_id'] == $tARow['b_company_code']){?>selected<?}?>><?=$tRow['bc_name']?></option>
                                <?}?>
                                </select>
                                <?}?>

                            </div>
 <!--                           <button class="btn btn-primary demo_1" type="button" id="confirm">确认</button>-->
                            <input type="hidden" value="" name="b_company_code"> 
                            <input type="hidden" value="" name="company_code"> 
                        </div>
                        <div id="policyno">
                            <label><strong>保单号</strong></label></br>
                            <div id="policynoDiv">  
                            </div>  
                        </div>
                        <div class="form-group">
                            <span class="help-block">权限分配&nbsp;&nbsp;&nbsp;&nbsp;</span>
                            <div id="auth"> 
                            <?foreach($tCData as $v){?>
                            <input type="checkbox" id="active<?=$v['id']?>" name="auth[]" value="<?=$v['id']?>" <?if(in_array($v['id'],$tCArr)){?>checked<?}?>/><label for="active<?=$v['id']?>">&nbsp;<?=$v['name']?>&nbsp;&nbsp;&nbsp;&nbsp;</label>
                            <?}?>
                            </div>
                        </div>
                        <button class="btn btn-primary demo_2" type="button" id="submit">修改</button>
                        <input type='hidden' value="<?=$pId?>" name="id" />
                    </form>   
                </div>
                <div class="subviews">
                    <div class="subviews-container"></div>
                </div>
            </div>
            <!-- end: PAGE -->
        </div>
    </div>
</div>
<!-- end: MAIN CONTAINER -->
<script type="text/javascript" src="/plugins/jquery-ui-1.11.4/jquery-ui.min.js"></script>
 <script type="text/javascript" src="/plugins/medialog/mdialog.js"></script><!--medialog -->
 <script type="text/javascript" src="/plugins/medialog/zepto.min.js"></script><!--zepto -->
<script>
$(function(){
    $('select[name="bcompany"]').on("change",function(){
        var company_id = $('input[name="company"]').val();
        var role = '<?=$tARow['role']?>';
        if(role == 'qy_admin'){
            var bc_id = $(this).val();
            policyno('bc_id='+bc_id);
        }else{
            var bc_id = $(this).val();
            policyno('insurance_no='+company_id+'&organition_no='+bc_id);
        }

    });
    $('#submit').click(function(){
    
        var data = $('form[name="myform"]').serialize();
        $.post('/admin_admin/edit',data,function(obj){
            cg_alert_edit(obj,'/admin_admin/','/admin_admin/edit?id=<?=$pId?>'); 
        });
    });
    policynoinit();
})

function policynoinit(){
    var company_id = $('input[name="company"]').val();
    var b_company_id = $('input[name="b_company"]').val();
    var role = '<?=$tARow['role']?>';

    if(b_company_id == 0){ //公司
        if(role == 'qy_admin'){
            policyno('c_id='+company_id);
        }else{
            policyno('insurance_no='+company_id);
        } 
    }else{//分公司
        if(role == 'qy_admin'){
            policyno('bc_id='+b_company_id);
        }else{
            policyno('insurance_no='+company_id+'&organition_no='+b_company_id);
        }
    }

}
function in_array(search,array){
    for(var i in array){
        if(array[i]==search){
            
            return true;
        }
    }
    return false;
}
//保单
function policyno(data){
    var carr = <?=json_encode(explode(',',$tARow['policy_no']))?>;
    $.get('/admin_admin/policy?'+data,function(obj){
        var html = '';
        $.each(obj.data,function(key,row){
            if(in_array(row.policyno,carr)){
                html += '<input type="checkbox" value="'+row.policyno+'" name="policyno[]" checked/>'+row.policyno; 
            }else{
                html += '<input type="checkbox" value="'+row.policyno+'" name="policyno[]" />'+row.policyno; 
            }
        });
        $('#policynoDiv').html(html);
    });
}
//权限
function rolelist(){
    var role = $('input[name="role"]:checked').val();
    $.get('/admin_admin/role?role='+role,function(obj){
        var html = '';
        $.each(obj.data,function(key,row){
            html += '<input type="checkbox" value="'+row.id+'" name="auth[]"/>'+row.name;
        });
        $('#auth').html(html);
    });

}

$('label[for="passwd"]').mouseover(function(){
    $(this).css('cursor','pointer');
    $(this).click(function(){
        $('#passwd').removeClass('hidden');
    });
});
</script>

<?php include PATH_TPL."/admin/tpl.footer.phtml"?>
